<?php

namespace app\admin\controller;

use app\common\controller\Backend;
use think\Db;

/**
 *
 *
 * @icon fa fa-circle-o
 */
class Selectlist extends Backend
{
    protected $noNeedLogin = ['*'];

    public function index($tablename = '',$year = '') {
        $where = [];
        if($tablename == 'activity')
            $where['year'] = ['in',[0,$year]];//date('Year')
        if($tablename=='carrier')
            $res = Db::name($tablename)->where($where)->order('sort')->select();
        elseif($tablename=="leaders"){
            // $res = Db::name('admin')
            //     -> alias('a')
            //     -> field('a.id,a.nickname,a.nickname as name')
            //     -> join('auth_group_access b',"a.id=b.uid ")
            //     -> where(['b.group_id' => GROUP_LEADER,'a.is_select'    => 1])
            //     -> select();
            $res = Db::name('leaders')->order('sort asc')-> select();
        }else
            $res = Db::name($tablename)->where($where)->select();

        foreach ($res as $kk=> $vv) {
            $options[$vv['id']] = $vv['name'];
        }
        return json($options);
    }

    public function leader() {
        $res = Db::name('admin') -> alias('a')-> field('a.id,a.nickname,a.nickname as name') ->join('auth_group_access b',"a.id=b.uid ")
            ->where(['b.group_id' => GROUP_LEADER])->select();
        foreach ($res as $kk=> $vv) {
            $options[$vv['id']] = $vv['name'];
        }

        return json($options);
    }

    public function progress(){
        $library_id = $this->request->get('library_id');
        $where = [];
        if($library_id)
            $where['library_id'] = $library_id;
        $res = Db::name('progress')->where($where)->select();
        foreach ($res as $kk=> $vv) {
            $options[$vv['id']] = $vv['name'];
        }
        return json($options);
    }

    public function state(){
        $options = ['终止'=>'终止','暂停'=>'暂停','在谈'=>'在谈','框架'=>'框架','正式'=>'正式','注册'=>'注册','开工'=>'开工','运营'=>'运营'];
        return json($options);
    }

    public function street(){
        // $library_id = $this->request->get('library_id');
        $where = ['group_id'=>5];

        $res = Db::name('chargedep')->where($where)->select();
        foreach ($res as $kk=> $vv) {
            $options[$vv['id']] = $vv['name'];
        }
        return json($options);
    }


}
